package com.yanq.liancar.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.view.RxToast;
import com.yanq.liancar.R;
import com.yanq.liancar.bean.BaseBean;
import com.yanq.liancar.bean.VerificationCodeBean;
import com.yanq.liancar.url.Config;
import com.yanq.liancar.util.LogUtils;
import com.yanq.liancar.util.Utils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class FindPwdStepTwoActivity extends AppCompatActivity {
    @BindView(R.id.back_btn)
    ImageView backBtn;
    @BindView(R.id.gang)
    TextView gang;
    @BindView(R.id.phone_num)
    EditText phoneNum;
    @BindView(R.id.sms)
    EditText sms;
    @BindView(R.id.sure)
    TextView sure;
    private String phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.setStatusBar(this, true, false);
        setContentView(R.layout.activity_find_pwd_step_two);
        ButterKnife.bind(this);

        phone = getIntent().getStringExtra("phone");
        LogUtils.e("phone=====",phone);
    }


    //确认密码
    private void getRandomNum() {
        OkGo.<String>post(Config.s + "llc/updatePwd")
                .tag(this)
                .params("tel", phone)
                .params("pwd1",phoneNum.getText().toString().trim() )
                .params("pwd2",sms.getText().toString().trim() )
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        Gson gson = new Gson();
                        BaseBean baseBean=gson.fromJson(response.body(),BaseBean.class);
                        if (baseBean.isIsSuccess()){
                            RxToast.success("密码修改成功");
                            RxActivityTool.skipActivity(FindPwdStepTwoActivity.this, LoginActivity.class);
                        }else {
                            RxToast.error(baseBean.getOutputMessage());
                        }

                    }
                });
    }

    @OnClick({R.id.back_btn, R.id.sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                finish();
                break;
            case R.id.sure:
                getRandomNum();
                break;
        }
    }
}
